package com.vcc.boss.controller;

import com.vcc.core.annotations.RestPack;
import com.vcc.core.model.Result;
import com.vcc.core.util.IdWorker;
import com.vcc.boss.core.component.OssComponent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.net.URL;

@RestController
@RequestMapping("upload")
public class UploadController {

    @Autowired
    private OssComponent ossComponent;


    @RestPack
    @PostMapping("upload")
    public Result<String> upload(@RequestBody MultipartFile file){
        String filename = IdWorker.getStringOrderId() + ".jpg";
        return Result.returnGenEriCity(ossComponent.uploadFile(file,filename));
    }

    @RestPack
    @GetMapping("remove")
    public Boolean remove(String fileName){
        return ossComponent.remove(fileName);
    }

    @RestPack
    @GetMapping("generateTokenUrl")
    public URL generateTokenUrl(String fileName){
        return ossComponent.generateTokenUrl(fileName);
    }

}
